package com.op.model.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.op.entity.Menu;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName： MenuTreeVo
 * Date： 2021/12/25 17:07
 *
 * @author 孤焰
 * @version 1.0
 **/

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("下拉选择菜单")
public class SelectMenuVo implements Serializable {
    private static final long serialVersionUID = 4361083250941985007L;

    @ApiModelProperty("主键id")
    private Long id;

    @ApiModelProperty("节点名称")
    private String label;

    @ApiModelProperty("子菜单")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<SelectMenuVo> children;

    public SelectMenuVo(Menu menu) {
        this.id = menu.getId();
        this.label = menu.getName();
        this.children = menu.getChildren().stream()
                .map(SelectMenuVo::new)
                .collect(Collectors.toList());
    }
}
